const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
/**
 *  获取数组对象的不同
 * @param { Array } arr1 
 * @param { Array } arr2 
 */
function getArrDifference(arr1, arr2) {
  var newArr = [];
  for (var i = 0; i < arr2.length; i++) {
    var isExist = false;
    for (var j = 0; j < arr1.length; j++) {
      if (arr2[i].id == arr1[j].id) {
        isExist = true;
        break;
      }
    }
    if (!isExist) {
      newArr.push(arr2[i]);
    }
  }
  return newArr;
};

const httpToHttps = (url) => {
  if (!url) return
  if (url.indexOf('https') < 0) url = url.replace('http', 'https')
  return url
}

module.exports = {
  formatTime: formatTime,
  getArrDifference: getArrDifference,
  httpToHttps
}